package com.cyandpos.pad.refund.model;

import android.text.TextUtils;
import android.util.Log;

import com.cyandpos.pad.common.commondata.BaseResponse;
import com.cyandpos.pad.common.netmanager.PosHttpManager;
import com.cyandpos.pad.http.OkHttpUtils;
import com.cyandpos.pad.posdata.BackUploadResult;
import com.cyandpos.pad.posdata.Member;
import com.cyandpos.pad.posdata.PrepareRefundData;
import com.cyandpos.pad.posdata.QueryMemberReq;
import com.cyandpos.pad.refund.contract.UploadRefundContract;
import com.google.gson.JsonObject;

public class UploadRefundModelImpl implements UploadRefundContract.Model {
    @Override
    public void upLoadBackGoods(PrepareRefundData backUploadReq, final OnCompleteListener completeListener) {
        PosHttpManager.backUpLoadGoods2CrmRequestParam(backUploadReq, new OkHttpUtils.ResultCallback() {
            @Override
            public void onSuccess(JsonObject response) {
                BaseResponse<BackUploadResult> baseResponse = BaseResponse.fromJson(response.toString(), BackUploadResult.class);
                if (baseResponse.getCode().equals("0")){
                    completeListener.onSuccess(baseResponse.getData());
                }else {
                    if (TextUtils.isEmpty(baseResponse.getTips())){
                        onFailure(baseResponse.getMsg());
                    }else {
                        onFailure(baseResponse.getTips());
                    }
                    
                }
            }

            @Override
            public void onFailure(String msg) {
                completeListener.onFailure(msg);
            }
        });
    }

    @Override
    public void getVipInfo(QueryMemberReq memberReq, final OngetVipInfoCompleteListener listener) {
        PosHttpManager.QueryMemberExecute(memberReq, new OkHttpUtils.ResultCallback() {
            @Override
            public void onSuccess(JsonObject response) {
                BaseResponse<Member> baseResponse = BaseResponse.fromJson(response.toString(),Member.class);
                if(baseResponse.getCode().equals("0")){
                    listener.onGetVipSuccess(baseResponse.getData());
                }else {
                    if (TextUtils.isEmpty(baseResponse.getTips())){
                        listener.onGetVipFailure(baseResponse.getMsg());
                    }else {
                        listener.onGetVipFailure(baseResponse.getTips());
                    }

                }

            }

            @Override
            public void onFailure(String msg) {
                listener.onGetVipFailure(msg);

            }
        });
    }
    /**
     * 封装错误信息
     * @param resCode
     * @param Msg
     * @return
     */
    private String getErrorMsg(String resCode, String Msg) {
        return "返回码:" + resCode + ",错误信息:" + Msg;
    }
}
